Strange behaviour with regexp and DOORS 9.2

Hi all

We migrated from DOORS 8.2 to 9.2 and I found a strange behaviour with the regexp function. It doesn't work with DOORS 8.2 as with DOORS 9.2 (same with regexp2) and it has a strange behaviour with DOORS 9.2

Here is my function :
 

string linkNextValue(string &s) 
{
    string result = ""
    Regexp hasField = regexp "(^|[ ,;\t\n]*)([^,;\t\n]*[^ ,;\t\n])($|[ ,;\t\n]+)"
 
    while ((null result) and (! null s))
    {
        hasField s
        result = s[match 2]
        s = s[end(0)+1:]
    }
 
    delete hasField 
 
    return result
}
 
string strAppList= "V2.3.1P"
string strApplicability 
 
while (!null strAppList)
{
    strApplicability = linkNextValue(strAppList)
}
 
print strApplicability

 


When you execute this code(should return the last value of the string), the result is empty !!! (whereas with DOORS 8.2, the result was "V2.3.1P")

Then remplace "V2.3.1P" by "V2.3.1P;V2.4.1" and run the code. It returns "V2.4.1"

Then remplace again "V2.3.1P;V2.4.1" by "V2.3.1P" and run the code again. It returns "V2.3.1P". This is the good result I expected first !!!

Any idea about this behaviour ?

Thanks and regards

David

 


SystemAdmin - Tue Aug 23 04:13:38 EDT 2011

Re: Strange behaviour with regexp and DOORS 9.2
llandale - Tue Aug 23 12:09:25 EDT 2011

Its advertised that they changed the internal Regular expression engine as part of the "blue washing" and that regular expression may not work identically and that you should test each one. Not sure what "regexp2" does but they say use that from now one.

Having said that, your regexp looks odd:
1: (^|[ ,;\\t\\n]*)
2: ([^,;\\t\\n]*[^ ,;\\t\\n])
3: ($|[ ,;\\t\\n]+)"

1: Not sure when "^" is inside the paren whether it means "start of string" or "not". Anyway, this seems to say "not or zero or more delimiters", which doesn't make sense to me.

2: this seems to say "zero or more non-delimiter characters followed by one non-delimiter-non-space character". That's basically an alpha-string that doesn't end in space. OK.

3: Don't know what $ means when its not at the end of a string, but this looks like you want one or more delimiter. Not sure what you are "or"ing here.

I think you want to strip off each valid field in the input string, fields are separated by those delimiters.
o I see you have two loops when you only need one.
o I've re-written the Regular expression
o You should defined that OUTSIDE the function as its especially slow, and will bog you down if you do it 1000s of times.
This seems to work, but I din't try wierd combinations including spaces:

const string    cl_re_strAnyChar = "[" charOf(1)"-" charOf(255)"]"        // Any ascii character except null
 
string ReString =       "^"                                   // start of string -
                                "([ ,;\t\n]*)"                        // zero or more delimiters      -
                                "([^,;\t\n]*[^ ,;\t\n])"      // one or more non-delimiters
 
//print "ReString = <<<<<" ReString ">>>>>\n"
 
Regexp hasField = regexp (ReString)
 
string linkNextValue(string &s) 
{
    string result
 
    if (hasField s)
    {
        result = s[match 2]
        s = s[end(0)+1:]
    }
    else
    {  result = ""
       s = ""
    }
 
    return result
}
 
 
void    RunTest(string InString)
{
        string strApplicability 
        string  Remainder = InString
        int     FieldNum = 0
        
        print "=============" InString "=============\n"
 
        while (!null Remainder)
        {
                strApplicability = linkNextValue(Remainder)
                print "\t" (FieldNum++) "\t^" strApplicability "^\n"
        }
}
 
RunTest("A;B;C ;D")
RunTest("V2.3.1P; jdjdk")
RunTest("V2.3.1P ;dd d.,dd")
RunTest("V2.3.1P;;;")
 
delete hasField 
// ============= It produces this in v92:
=============A;B;C ;D=============
        0       ~A~
        1       ~B~
        2       ~C~
        3       ~D~
=============V2.3.1P; jdjdk=============
        0       ~V2.3.1P~
        1       ~jdjdk~
=============V2.3.1P ;dd d.,dd=============
        0       ~V2.3.1P~
        1       ~dd d.~
        2       ~dd~
=============V2.3.1P;;;=============
        0       ~V2.3.1P~
        1       ~~

 


Notice that linkNextValue() returns null when "s" is null or poorly formed.

 

 

  • Louie

Go here and 'find' "greedy". I thought I was going to need that but I didn't.
http://en.wikipedia.org/wiki/Regular_expression

 

Re: Strange behaviour with regexp and DOORS 9.2
SystemAdmin - Wed Aug 24 03:44:02 EDT 2011

llandale - Tue Aug 23 12:09:25 EDT 2011

Its advertised that they changed the internal Regular expression engine as part of the "blue washing" and that regular expression may not work identically and that you should test each one. Not sure what "regexp2" does but they say use that from now one.

Having said that, your regexp looks odd:
1: (^|[ ,;\\t\\n]*)
2: ([^,;\\t\\n]*[^ ,;\\t\\n])
3: ($|[ ,;\\t\\n]+)"

1: Not sure when "^" is inside the paren whether it means "start of string" or "not". Anyway, this seems to say "not or zero or more delimiters", which doesn't make sense to me.

2: this seems to say "zero or more non-delimiter characters followed by one non-delimiter-non-space character". That's basically an alpha-string that doesn't end in space. OK.

3: Don't know what $ means when its not at the end of a string, but this looks like you want one or more delimiter. Not sure what you are "or"ing here.

I think you want to strip off each valid field in the input string, fields are separated by those delimiters.
o I see you have two loops when you only need one.
o I've re-written the Regular expression
o You should defined that OUTSIDE the function as its especially slow, and will bog you down if you do it 1000s of times.
This seems to work, but I din't try wierd combinations including spaces:

const string    cl_re_strAnyChar = "[" charOf(1)"-" charOf(255)"]"        // Any ascii character except null
 
string ReString =       "^"                                   // start of string -
                                "([ ,;\t\n]*)"                        // zero or more delimiters      -
                                "([^,;\t\n]*[^ ,;\t\n])"      // one or more non-delimiters
 
//print "ReString = <<<<<" ReString ">>>>>\n"
 
Regexp hasField = regexp (ReString)
 
string linkNextValue(string &s) 
{
    string result
 
    if (hasField s)
    {
        result = s[match 2]
        s = s[end(0)+1:]
    }
    else
    {  result = ""
       s = ""
    }
 
    return result
}
 
 
void    RunTest(string InString)
{
        string strApplicability 
        string  Remainder = InString
        int     FieldNum = 0
        
        print "=============" InString "=============\n"
 
        while (!null Remainder)
        {
                strApplicability = linkNextValue(Remainder)
                print "\t" (FieldNum++) "\t^" strApplicability "^\n"
        }
}
 
RunTest("A;B;C ;D")
RunTest("V2.3.1P; jdjdk")
RunTest("V2.3.1P ;dd d.,dd")
RunTest("V2.3.1P;;;")
 
delete hasField 
// ============= It produces this in v92:
=============A;B;C ;D=============
        0       ~A~
        1       ~B~
        2       ~C~
        3       ~D~
=============V2.3.1P; jdjdk=============
        0       ~V2.3.1P~
        1       ~jdjdk~
=============V2.3.1P ;dd d.,dd=============
        0       ~V2.3.1P~
        1       ~dd d.~
        2       ~dd~
=============V2.3.1P;;;=============
        0       ~V2.3.1P~
        1       ~~

 


Notice that linkNextValue() returns null when "s" is null or poorly formed.

 

 

  • Louie

Go here and 'find' "greedy". I thought I was going to need that but I didn't.
http://en.wikipedia.org/wiki/Regular_expression

 

Thanks Louie for this complete answer and your advice

My concern was mainly that my code doesn't return the same result when you execute it twice and that's what worries me !!!

Even if I create new regexp, how can I be sure it will always work !!!

We post a case to IBM. They replied with an incomprehensible explanation (In french and I'm French ;-)). So we asked them a more clear explanation

Regards

Re: Strange behaviour with regexp and DOORS 9.2
OurGuest - Wed Aug 24 08:57:26 EDT 2011

I am wondering why you return the original value as null using the following line of code.
 

string linkNextValue(string &s)